package com.mql.ganio.ui.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;

import com.mql.ganio.R;
import com.mql.ganio.model.bean.AndroidBean;
import com.mql.ganio.ui.base.baseadapter.BaseRecyclerViewAdapter;
import com.mql.ganio.ui.base.baseadapter.BaseRecyclerViewHolder;
import com.mql.ganio.util.CommonUtils;

import java.util.List;

/**
 * 作者：Administrator on 2017/11/10 14:06
 */
public class EverydayAdapter extends BaseRecyclerViewAdapter<List<AndroidBean>, BaseRecyclerViewHolder> {
    private static final int TYPE_TITLE = 1; // title
    private static final int TYPE_ONE = 2;// 一张图
    private static final int TYPE_TWO = 3;// 二张图
    private static final int TYPE_THREE = 4;// 三张图
    List<List<AndroidBean>> lists;

    @Override
    public int getItemViewType(int position) {
        if (!TextUtils.isEmpty(lists.get(position).get(0).getType_title())) {
            return TYPE_TITLE;
        } else if (lists.get(position).size() == 1) {
            return TYPE_ONE;
        } else if (lists.get(position).size() == 2) {
            return TYPE_TWO;
        } else if (lists.get(position).size() == 3) {
            return TYPE_THREE;
        }
        return super.getItemViewType(position);
    }

    public EverydayAdapter(Context context, List<List<AndroidBean>> mList) {
        super(context, mList);
        this.lists = mList;
    }

    @Override
    public BaseRecyclerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view;
        switch (viewType) {
            case TYPE_TITLE:
                view = mLayoutInflater.inflate(R.layout.item_everyday_title, parent, false);
                return new BaseRecyclerViewHolder(context, view);
            case TYPE_ONE:
                view = mLayoutInflater.inflate(R.layout.item_everyday_one, parent, false);

                return new BaseRecyclerViewHolder(context, view);
            case TYPE_TWO:
                view = mLayoutInflater.inflate(R.layout.item_everyday_two, parent, false);

                return new BaseRecyclerViewHolder(context, view);
            default:
                view = mLayoutInflater.inflate(R.layout.item_everyday_three, parent, false);
                return new BaseRecyclerViewHolder(context, view);
        }
    }


    @Override
    public void onBindViewHolder(BaseRecyclerViewHolder holder, int position) {
        super.onBindViewHolder(holder, position);
        List<AndroidBean> beanList = lists.get(position);
        switch (getItemViewType(position)) {
            case TYPE_TITLE:
                if (position != 0) {
                    holder.getView(R.id.view_line).setVisibility(View.VISIBLE);
                } else {
                    holder.getView(R.id.view_line).setVisibility(View.GONE);
                }
                int index = 0;
                String title = beanList.get(0).getType_title();
                holder.setText(R.id.tv_title_type, title);
                if ("Android".equals(title)) {
                    holder.setImageDrawable(R.id.iv_title_type, CommonUtils.getDrawable(R.drawable.home_title_android));
                    index = 0;
                } else if ("福利".equals(title)) {
                    holder.setImageDrawable(R.id.iv_title_type, CommonUtils.getDrawable(R.drawable.home_title_meizi));
                    index = 1;
                } else if ("IOS".equals(title)) {
                    holder.setImageDrawable(R.id.iv_title_type, CommonUtils.getDrawable(R.drawable.home_title_ios));
                    index = 2;
                } else if ("休息视频".equals(title)) {
                    holder.setImageDrawable(R.id.iv_title_type, CommonUtils.getDrawable(R.drawable.home_title_movie));
                    index = 2;
                } else if ("拓展资源".equals(title)) {
                    holder.setImageDrawable(R.id.iv_title_type, CommonUtils.getDrawable(R.drawable.home_title_source));
                    index = 2;
                } else if ("瞎推荐".equals(title)) {
                    holder.setImageDrawable(R.id.iv_title_type, CommonUtils.getDrawable(R.drawable.home_title_xia));
                    index = 2;
                } else if ("前端".equals(title)) {
                    holder.setImageDrawable(R.id.iv_title_type, CommonUtils.getDrawable(R.drawable.home_title_qian));
                    index = 2;
                } else if ("App".equals(title)) {
                    holder.setImageDrawable(R.id.iv_title_type, CommonUtils.getDrawable(R.drawable.home_title_app));
                    index = 2;
                }
                final int finalIndex = index;
                break;
            case TYPE_ONE:
                if ("福利".equals(beanList.get(0).getType())) {
                    holder.getView(R.id.tv_one_photo_title).setVisibility(View.GONE);
//                    holder.getView(R.id.iv_one_photo).setScaleType(ImageView.ScaleType.CENTER_CROP);
                    holder.setImageView(R.id.iv_one_photo, beanList.get(0).getUrl());


                } else {
                    holder.getView(R.id.tv_one_photo_title).setVisibility(View.VISIBLE);
                    holder.setText(R.id.tv_one_photo_title, beanList.get(0).getDesc());
                    holder.setImageView(R.id.iv_one_photo, beanList.get(0).getImage_url());
                }
                holder.getView(R.id.iv_one_photo).setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

                    }
                });
                break;
            case TYPE_TWO:
                holder.setImageView(R.id.iv_two_one_one, beanList.get(0).getImage_url());
                holder.setImageView(R.id.iv_two_one_two, beanList.get(1).getImage_url());

                holder.setText(R.id.tv_two_one_one_title, beanList.get(0).getDesc());
                holder.setText(R.id.tv_two_one_two_title, beanList.get(1).getDesc());
                holder.getView(R.id.ll_two_one_one).setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

                    }
                });
                holder.getView(R.id.ll_two_one_two).setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

                    }
                });
                break;
            default:
                holder.setImageView(R.id.iv_three_one_one,beanList.get(0).getImage_url());
                holder.setImageView(R.id.iv_three_one_two,beanList.get(1).getImage_url());
                holder.setImageView(R.id.iv_three_one_three,beanList.get(2).getImage_url());

                holder.setText(R.id.tv_three_one_one_title,beanList.get(0).getDesc());
                holder.setText(R.id.tv_three_one_two_title,beanList.get(1).getDesc());
                holder.setText(R.id.tv_three_one_three_title,beanList.get(2).getDesc());
                holder.getView(R.id.ll_three_one_one).setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

                    }
                });
                holder.getView(R.id.ll_three_one_two).setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

                    }
                });
                holder.getView(R.id.ll_three_one_three).setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

                    }
                });

                break;
        }
    }
}
